<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Personal extends Admin_Controller
{

    public function profile()
    {
        $uid            = $this->session->userdata('user_id');
        $member         = $this->user_m->get_user_by_user_id($uid);
        $data['member'] = $member;
        $this->load->view('personal/profile', $data);
    }

    public function update()
    {

        $post        = $this->input->post();
        $uid         = isset($post['user_id']) ? intval($post['user_id']) : false;
        $username    = isset($post['user']) ? htmlspecialchars($post['user'], ENT_QUOTES) : '';
        $getpassword = $this->input->post('user_password', true);
        if ($uid) {
            // 修改
            $admin = [
                'user_sex'   => $post['user_sex'],
                'user_tel'   => $post['user_tel'],
                // 'user_qq'    => $post['user_qq'],
                'user_email' => $post['user_email'],
            ];
            if (!empty($username)) {
                $admin['user_name'] = $username;
            }
            if (!empty($getpassword)) {
                $admin['user_salt']     = $salt = get_salt();
                $admin['user_password'] = password_dohash($getpassword, $salt);
            }
            $this->user_m->update_user($uid, $admin);
            show_message('修改个人资料成功', site_url(X_URL . 'home/index'), 1);
        } else {
            show_message('参数缺失', site_url(X_URL . 'personal/profile'), 1);
        }
    }
}